package Java7_Concurrency_Cookbook.fork_join.recursive_task_throw_exception;

import java.util.concurrent.ForkJoinPool;

/**
 * task.isCompletedAbnormally() 如果主任务或者它的子任务之一抛出了异常, 这个方法将返回true<br/>
 * 当任务抛出异常时, 会影响它的父任务, 以及父任务的父任务, 以此类推.
 * @author lixiangke
 * @date 2017/11/22
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        int[] array = new int[100];
        Task task = new Task(array, 0, 100);
        ForkJoinPool pool = new ForkJoinPool();
        pool.execute(task);
        pool.shutdown();
        //pool.awaitTermination(10, TimeUnit.SECONDS);
        if (task.isCompletedAbnormally()) {
            System.out.printf("Main: an exception has occurred\n");
            System.out.printf("Main: %s\n", task.getException());
        } else {
            System.out.println("ELSE");
        }
        System.out.printf("Main: Result: %d", task.join());
    }
}
